/* eslint-disable no-console */
/* eslint-disable camelcase */
export default class CanvasImage {
  set src(src) {
    this._src = src
    if (!this.onload) {
      return
    }
    my.getImageInfo({
      src,
      success: (res) => {
        this._width = res.width
        this._height = res.height
        this.onload()
      },
      fail: (err) => {
        if (this.onerror) {
          this.onerror(err.errMsg)
        }
      }
    })
  }

  get src() {
    return this._src
  }

  get width() {
    return this._width
  }

  get height() {
    return this._height
  }

  set onload(onload) {
    this._onload = onload
    return this._onload
  }

  get onload() {
    return this._onload
  }

  set onerror(onerror) {
    this._onerror = onerror
  }

  get onerror() {
    return this._onerror
  }
}
